﻿#region
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.IO;
using System.Data.OleDb;
using System.Text;
using System.Web.UI;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Net;
using System.Net.Sockets;
#endregion

namespace YTBZ
{
    public class BasePage : System.Web.UI.Page
    {

        /// <summary>
        /// 重写OnInit引发事件
        /// </summary>
        /// <param name="e">EventArgs</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Session.Add("SELECTSUPPLIER", "");  //当前用户选择的供应商清空
            ////base.Error += new EventHandler(Page_Error);
            ////验证用户登录
            //AdminUserCheck();
            //WinVal WinValInstance = new WinVal();
            //WinValInstance.ValStyle = "buttompoptip";
            //WinValInstance.SetValidator();

            //关联错误事件处理程序
            //this.Error += new System.EventHandler(BasePage_Error);
            //Init += new EventHandler(BasePage_Init);
            this.PreRender += new EventHandler(BasePage_RreRender);

        }

        #region 人员帐号(Acc)
        /// <summary>
        /// 人员帐号
        /// </summary>
        public static String CURRUSERIDS
        {
            get
            {
                return HttpContext.Current.Session["CURRUSERID"] != null ? HttpContext.Current.Session["CURRUSERID"].ToString() : null;
            }
        }
        #endregion
        #region 判断Session是否过期，以及访问权限的判断
        /// <summary>
        /// 判断Session是否过期，以及访问权限的判断
        /// </summary>
        /// <param name="str_url"> 转向的页面地址</param>
        /// <returns>没有过期或有权限返回true，否则返回false</returns>
        public static bool Check_Session(string str_url)
        {
            if (CURRUSERIDS == null)
            {
                HttpContext.Current.Response.Write("<Script Language=\"javascript\">\n");
                HttpContext.Current.Response.Write("alert(\"您没登录或您的登录后长时间未操作，请重新登录!\")\n");
                HttpContext.Current.Response.Write("parent.location.href='/login.aspx'\n");
                HttpContext.Current.Response.Write("</Script>");
                return false;
            }
            return true;
        }

        #endregion

        #region 错误日志 
        public void proSaveErro(string ex)
        {
            DB TT = new DB();
            TT.txtSaveErro("\r\n" + ex);
        }
        public void proSaveIOErro(string ex)
        {
            DB TT = new DB();
            TT.txtSaveIOErro("\r\n" + ex);
        }
        public void proSaveErro(Exception ex)
        {
            string sErrorMsg = "页面错误：[" + DateTime.Now + "]\r\n";
            sErrorMsg += "操作人员帐号：[" + CURRUSERID + "]  操作人姓名：["
                + CURRUSERNAME + " " + "]  操作人所属机构：[" + CURRUSERDEPTNAME + "]\r\n";
            sErrorMsg += HttpContext.Current.Request.Url + "发生错误。";
            sErrorMsg += "错误信息：\r\n" + ex.Message + "\r\n";
            sErrorMsg += "调试跟踪：" + ex.StackTrace;
            DB TT = new DB();
            TT.txtSaveErro(sErrorMsg);
        }
        public DataTable proGetDT(SortedList SLData, string spName)
        {
            DB TT = new DB();
            return TT.proGetDT(SLData, spName);
        }
        public string proGetDTOne(SortedList SLData, string spName)
        {
            DB TT = new DB();
            return TT.proGetDTOne(SLData, spName);
        }
        public string proSetDT(SortedList SLData, string spName)
        {
            DB TT = new DB();
            return TT.proSetDT(SLData, spName);
        }
        /// <summary>
        /// 写系统日志
        /// </summary>
        /// <param name="strMsgType">操作类别</param>
        /// <param name="strMsgMode">操作模块</param>
        /// <param name="strMsgInfo">操作信息</param>
        /// <param name="strMaterialCode">物料编号</param>
        /// <param name="strMaterialName">物料名称</param>
        /// <param name="strSupplierCode">供应商编号</param>
        /// <param name="strSupplierName">供应商名称</param>
        public void proREG(string strMsgType, string strMsgMode, string strMsgInfo,
                           string strMaterialCode, string strMaterialName, string strSupplierCode, string strSupplierName)
        {
            proREG(strMsgType, strMsgMode, strMsgInfo,
                    strMaterialCode, strMaterialName, strSupplierCode, strSupplierName, null);
        }
        /// <summary>
        /// 写系统日志
        /// </summary>
        /// <param name="strMsgType">操作类别</param>
        /// <param name="strMsgMode">操作模块</param>
        /// <param name="strMsgInfo">操作信息</param>
        /// <param name="strMaterialCode">物料编号</param>
        /// <param name="strMaterialName">物料名称</param>
        /// <param name="strSupplierCode">供应商编号</param>
        /// <param name="strSupplierName">供应商名称</param>
        /// <param name="strBaseInfo">基地信息（基地名称/工厂信息）</param>
        public void proREG(string strMsgType, string strMsgMode, string strMsgInfo,
                           string strMaterialCode, string strMaterialName, string strSupplierCode, string strSupplierName, string strBaseInfo)
        {
            //string IP = (Request.ServerVariables["HTTP_VIA"] != null) ? Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString() : Request.ServerVariables["REMOTE_ADDR"].ToString();

            SortedList SDList = new SortedList();
            SDList["V_MSGTYPE"] = strMsgType;
            SDList["V_MSGMODE"] = strMsgMode;
            SDList["V_MSGUSER"] = Session["CURRUSERNAME"] == null ? strMaterialCode : CURRUSERNAME;
            //SDList["V_MSGINFO"] = "[" + IP + "]" + strMsgInfo;
            SDList["V_MSGINFO"] = strMsgInfo;
            //SDList["V_MATERIALID"] = strMaterialID;
            SDList["V_MATERIALCODE"] = strMaterialCode;
            SDList["V_MATERIALNAME"] = strMaterialName;
            //SDList["V_SUPPLIERID"] = strSupplierID;
            SDList["V_SUPPLIERCODE"] = strSupplierCode;
            SDList["V_SUPPLIERNAME"] = strSupplierName;
            //基地信息
            if (strBaseInfo == "2032") { strBaseInfo = "临海基地"; }
            else if (strBaseInfo == "D355") { strBaseInfo = "晋中基地"; }
            SDList["V_BASEINFO"] = strBaseInfo;

            proSetDT(SDList, "PRO_SYS.MSGSAVE");
        }
        #endregion
        #region 权限处理 
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="strUserLogin">用户名</param>
        /// <param name="strUserPass">密码</param>
        /// <returns></returns>
        public string getUserLogin(string strUserLogin, string strUserPass)
        {

            #region 登录次件判断
            ArrayList Loginlist = new ArrayList();
            if (Session["arrayAdminLogin"] != null)//登录用户清单
                Loginlist = (ArrayList)Session["arrayAdminLogin"];
            //登录数组维护
            if (Session["AdminLogin"] != null && Session["AdminLogin"].ToString() != strUserLogin)//当前登录用户比对
            {
                int flag = 0;//Arraylist里是否有当当用户strUserLogin
                Session["AdminLogin"] = strUserLogin;
                for (int i = 0; i < Loginlist.Count; i += 3)
                {
                    if (Loginlist[i].ToString() == strUserLogin)
                    {
                        Session["AdminLoginSun"] = Loginlist[i + 1];//失败次数
                        Session["AdminLoginTime"] = Loginlist[i + 2];
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0)
                {
                    Session["AdminLoginSun"] = 0;
                    Session["AdminLogin"] = strUserLogin;
                    Session["AdminLoginTime"] = DateTime.Now;
                    Loginlist.Add(strUserLogin);//账号
                    Loginlist.Add("0");//失败次数
                    Loginlist.Add(Session["AdminLoginTime"].ToString());
                }
            }
            //失败超过5次
            if (Session["AdminLoginSun"] != null && Convert.ToInt32(Session["AdminLoginSun"]) >= 5)
            {
                if (Session["AdminLoginTime"] != null)
                {
                    DateTime FLoginTime = Convert.ToDateTime(Session["AdminLoginTime"]);
                    TimeSpan ts = DateTime.Now - FLoginTime;
                    if (ts.Minutes < 10)
                    {
                        return "对不起，5次登陆错误，10分钟后重试!";
                    }
                }
            }
            #endregion
            DB TT = new DB();
            TT.ClearCash();
            SortedList SDList = new SortedList();
            SDList["V_USERLOGIN"] = strUserLogin;
            SDList["V_USERPASS"] = TT.MD5PHP(strUserPass);
            DataTable dt = TT.proGetDT(SDList, "PRO_SYS.USERLOGIN");
            if (dt != null && dt.Rows.Count == 1)
            {
                Session["AdminLogin"] = null;
                Session["AdminLoginSun"] = null;
                Session["arrayAdminLogin"] = null;
                Session["AdminLoginTime"] = null;
                Session.Add("CURRUSERID", dt.Rows[0]["USERID"].ToString());
                Session.Add("CURRUSERNAME", dt.Rows[0]["USERNAME"].ToString());
                Session.Add("CURRUSERLOGIN", dt.Rows[0]["USERLOGIN"].ToString());
                Session.Add("CURRUSERCODE", dt.Rows[0]["USERCODE"].ToString());
                Session.Add("CURRUSERDEPTID", dt.Rows[0]["DEPTID"].ToString());
                // Session.Add("CURRUSERDEPTNAME", dt.Rows[0]["DEPTNAME"].ToString());
                Session.Add("CURRUSEROTHROLE", dt.Rows[0]["OTHROLE"].ToString() == "" ? "00000000000000000000000000000000" : dt.Rows[0]["OTHROLE"].ToString());
                Session.Add("CURRUSERTYPE", dt.Rows[0]["USERTYPE"].ToString());

                DateTime overTime = DateTime.Now.AddMonths(-3); //系统当前时间往前推3个月
                DateTime passUpdateTime = Convert.ToDateTime(dt.Rows[0]["PASSUPDATETIME"]);
                if (DateTime.Compare(overTime, passUpdateTime) > 0)
                {
                    return "OVER密码过期，请更改密码后再登陆！";
                }
                return "";
            }
            else
            {
                #region 记录登录失败次数
                if (Session["AdminLoginSun"] == null)
                {
                    Session["AdminLoginSun"] = 1;
                    Session["AdminLogin"] = strUserLogin;
                    Session["AdminLoginTime"] = DateTime.Now;
                    Loginlist.Add(strUserLogin);//账号
                    Loginlist.Add("1");//失败次数
                    Loginlist.Add(Session["AdminLoginTime"].ToString());
                }
                else
                {
                    Session["AdminLoginSun"] = Convert.ToInt32(Session["AdminLoginSun"]) + 1;
                    for (int i = 0; i < Loginlist.Count; i += 3)
                    {
                        if (Loginlist[i].ToString() == strUserLogin)
                        {
                            Loginlist[i + 1] = Session["AdminLoginSun"].ToString();//失败次数
                            break;
                        }
                    }
                }
                Session["arrayAdminLogin"] = Loginlist;

                string m = "1";
                if (Session["AdminLoginSun"] != null)
                    m = Session["AdminLoginSun"].ToString();
                return "用户名或密码输入有误（" + m + "次），请检查确认！";
                #endregion
            }
        }
        /// <summary>
        /// 获取用户权限菜单
        /// </summary>
        /// <param name="strUserRole">用户权限</param>
        /// <returns></returns>
        public DataTable getUserMenu(string strUserRole)
        {
            SortedList SDListMenu = new SortedList();
            SDListMenu["V_USERROLE"] = strUserRole;
            DB TT = new DB();
            DataTable dtMenu = TT.proGetDT(SDListMenu, "PRO_SYS.USERMENU");
            return dtMenu;
        }
        #region 用户属性
        /// <summary>
        /// 当前用户ID
        /// </summary>
        public string CURRUSERID
        {
            get
            {
                string strCurrID = (Session["CURRUSERID"] == null ? "" : Session["CURRUSERID"].ToString());
                return strCurrID;
                //if (strCurrID == "") { Response.Write("<script language=javascript>parent.location='../Login.aspx';</script>"); return ""; }
                //else { return strCurrID; }
            }
        }
        /// <summary>
        /// 当前用户名称
        /// </summary>
        public string CURRUSERNAME
        {
            get
            {
                string strCurrName = (Session["CURRUSERNAME"] == null ? "" : Session["CURRUSERNAME"].ToString());
                return strCurrName;
                //if (strCurrName == "") { Response.Write("<script language=javascript>parent.location='../Login.aspx';</script>"); return ""; }
                //else { return strCurrName; }
            }
        }
        /// <summary>
        /// 当前用户登陆名
        /// </summary>
        public string CURRUSERLOGIN { get { return (Session["CURRUSERLOGIN"] == null ? "" : Session["CURRUSERLOGIN"].ToString()); } }
        /// <summary>
        /// 当前用户工号
        /// </summary>
        public string CURRUSERCODE { get { return (Session["CURRUSERCODE"] == null ? "" : Session["CURRUSERCODE"].ToString()); } }
        /// <summary>
        /// 当前用户部门ID
        /// </summary>
        public string CURRUSERDEPTID { get { return (Session["CURRUSERDEPTID"] == null ? "" : Session["CURRUSERDEPTID"].ToString()); } }
        /// <summary>
        /// 当前用户部门名称
        /// </summary>
        public string CURRUSERDEPTNAME { get { return (Session["CURRUSERDEPTNAME"] == null ? "" : Session["CURRUSERDEPTNAME"].ToString()); } }
        /// <summary>
        /// 当前用户类型
        /// </summary>
        public string CURRUSERTYPE { get { return (Session["CURRUSERTYPE"] == null ? "" : Session["CURRUSERTYPE"].ToString()); } }

        /// <summary>
        /// 撤销看板权限
        /// </summary>
        public string CURRUSEROTHROLE { get { return (Session["CURRUSEROTHROLE"] == null ? "" : Session["CURRUSEROTHROLE"].ToString()); } }
        #endregion
        /// <summary>
        /// 用户密码修改
        /// </summary>
        /// <param name="strOld">旧密码</param>
        /// <param name="strNew">新密码</param>
        /// <param name="strConfrim"></param>
        /// <returns></returns>
        public string getUserPasschange(string strOld, string strNew, string strConfrim)
        {
            SortedList SDList = new SortedList();
            DB TT = new DB();
            SDList["V_USERID"] = CURRUSERID;
            SDList["V_USERPASSOLD"] = TT.MD5PHP(strOld);
            SDList["V_USERPASSNEW"] = TT.MD5PHP(strNew);
            SDList["V_USERPASSR"] = TT.MD5PHP(strConfrim);
            return TT.proSetDT(SDList, "PRO_SYS.USERPASS");
        }
        protected void Page_PreInit(Object sender, EventArgs e)
        {
            Page.Theme = "Default";
            //if (CURRUSERID == "")
            //{
            //    Response.Write("<script language=javascript>parent.location='../Login.aspx';</script>");
            //}
        }
        #region 扩展属性
        private string _keywords;
        private string _description;
        /// <SUMMARY>
        /// 获取或设置页的meta关键字

        /// </SUMMARY>
        public string Meta_Keywords
        {
            get
            {
                return _keywords;
            }
            set
            {
                // 删掉多余的空格



                // 译者注：\s匹配任何空白字符，包括空格、制表符、换页符等等。等价于 [\f\n\r\t\v]。



                _keywords = Regex.Replace(value, "\\s+", " ");
            }
        }

        /**/
        /// <SUMMARY>
        /// 获取或设置页的meta描述
        /// </SUMMARY>
        public string Meta_Description
        {
            get
            {
                return _description;
            }
            set
            {
                // 删掉多余的空格



                // 译者注：\s匹配任何空白字符，包括空格、制表符、换页符等等。等价于 [\f\n\r\t\v]。



                _description = Regex.Replace(value, "\\s+", " ");
            }
        }
        #endregion

        /// <summary>
        ///   页将使用这个基类初始化
        ///    如果可用则增加meta关键字和meta描述
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BasePage_RreRender(object sender, EventArgs e)
        {

            if (!String.IsNullOrEmpty(Meta_Keywords))
            {
                HtmlMeta tag = new HtmlMeta();
                tag.Name = "keywords";
                tag.Content = Meta_Keywords;
                Header.Controls.Add(tag);
            }

            if (!String.IsNullOrEmpty(Meta_Description))
            {
                HtmlMeta tag = new HtmlMeta();
                tag.Name = "description";
                tag.Content = Meta_Description;
                Header.Controls.Add(tag);
            }
            string Ver = string.Empty;
            if (System.IO.File.Exists(Server.MapPath("/version.xml")))    //有无版本号文件
            {
                DataSet ds = new DataSet();
                ds.ReadXml(Server.MapPath("/version.xml"));     //读取版本号

                if (ds.Tables.Count > 0)
                {
                    Ver = "(" + ds.Tables[0].Rows[0][0].ToString() + ")";
                }
            }
            if (Page.Title.IndexOf("noTail") >= 0)   //标题含（noTail）则不跟系统名称和版本号   20110310yexin添加
            {
                Page.Title = Page.Title.Replace("noTail", "");
            }
            else
            {
                Page.Title += "_" + System.Configuration.ConfigurationManager.AppSettings["SYSName"] + Ver;   //标题跟系统名称和版本号
            }
            Page.Title = Page.Title.Trim('_');
            //Page.Title += "_" + HttpContext.Current.Application["SiteName"].ToString();
        }
        #endregion

        //==========================================

        #region 弹出脚本 
        protected void jsOut(string strjs)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=javascript>" + strjs + "</script>");
        }
        public void jsWebClose()
        {
            jsOut(" window.close(); ");
        }
        public void jsMessage(string mes)
        {
            jsOut("alert('" + mes + "');");
        }
        public void jsJumpUrl(string url)
        {
            jsOut("self.location.href='" + url + "';");
        }

        //模态弹出 
        public void jsWindowOpenModal(string strPath)
        {
            jsWindowOpenModal(strPath, 1000, 760, "");
        }
        public void jsWindowOpenModal(string strPath, string flashBtn)
        {
            jsWindowOpenModal(strPath, 1000, 760, flashBtn);
        }
        public void jsWindowOpenModal(string strPath, int iWidth, int iHeight, string flashBtn)
        {
            string script = "window.showModalDialog('" + strPath + "'"
                + ",'','dialogWidth:" + iWidth.ToString() + "px,dialogheight:" + iHeight.ToString() + "px,"
                + "toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=yes,fullscreen=no,scrollbars=auto');"
                + (flashBtn == "" ? "" : "document.getElementById('" + flashBtn + "').click();");
            jsOut(script);
        }

        //普通弹出
        public void jsWindowOpen(string strPath)
        {
            jsWindowOpen(strPath, 1000, 760);
        }
        public void jsWindowOpen(string strPath, int iWidth, int iHeight)
        {
            string script = "var win = window.open('" + strPath + "'"
                + ",'MYTT','dialogWidth:" + iWidth.ToString() + "px,dialogheight:" + iHeight.ToString() + "px,"
                + " top=" + ((768 - iHeight) / 2).ToString() + "," + " left=" + ((1200 - iWidth) / 2).ToString() + ","
                + " toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=yes,fullscreen=no,scrollbars=yes');";
            jsOut(script);
        }
        #endregion

        #region 下拉字典类别
        public string DDL_TYPENAME { get { return "字典总类"; } }
        public string DDL_USERTYPE { get { return "用户类别"; } }
        public string DDL_USERTYPE_SUPPLIER { get { return "110200"; } } // 供应商用户
        public string DDL_MATERIALTYPE { get { return "物料类别"; } }
        public string DDL_CHESTTYPE { get { return "箱类别"; } }
        public string DDL_USETYPE { get { return "箱使用类别"; } }
        public string DDL_DLWLTYPE { get { return "对拉物料类别"; } }
        public string DDL_WARETYPE { get { return "仓库类别"; } }
        // public string DDL_STORETYPE { get { return "库存类别"; } }
        public string DDL_UNITID { get { return "单位"; } }
        public string DDL_NEEDTYPE { get { return "供货类别"; } }
        public string DDL_CLASSTYPE { get { return "排序件类别"; } }
        public string DDL_NEEDTYPE_DOWNLIMIT { get { return "610100"; } } //,'库存下限供货'
        public string DDL_NEEDTYPE_MOREDAY { get { return "610200"; } } //,'生产预期供货'
        public string DDL_NEEDTYPE_WARRBOARD { get { return "610300"; } } //,'红板报警供货'
        public string DDL_NEEDTYPE_WORKBOARD { get { return "610400"; } } //,'生产看板供货'
        public string DDL_NEEDTYPE_WARENEED { get { return "610900"; } } //,'库区指定供货'
        public string DDL_NEEDTYPE_OTHER { get { return "619900"; } } //,'其他方式供货' 
        public string DDL_KEEPTEAM { get { return "保管班组"; } }
        public string DDL_PDAROLE { get { return "PDA权限"; } }//PDA权限代码
        public string DDL_GOODOUTTYPE { get { return "出库类别"; } }
        public string DDL_GOODOUTTYPE_ORDER { get { return "810100"; } }//配套出库
        public string DDL_GOODOUTTYPE_CYCLE { get { return "810200"; } }//看板出库
        public string DDL_GOODOUTTYPE_CLASS { get { return "810300"; } }//排序出库
        public string DDL_GOODOUTTYPE_RED { get { return "810400"; } }//冲红出库
        public string DDL_GOODOUTTYPE_OTHER { get { return "819900"; } }//其他出库
        public string DDL_GOODINTYPE { get { return "入库类型"; } }
        public string DDL_GOODINTYPE_CHECK { get { return "320100"; } }//送检入库
        public string DDL_GOODINTYPE_NOCHECK { get { return "320200"; } }//免检入库
        public string DDL_GOODINTYPE_RECHECK { get { return "320300"; } }//复检入库
        public string DDL_GOODINTYPE_GIVE { get { return "320400"; } }//让步入库
        public string DDL_GOODINTYPE_DIRECT { get { return "320500"; } }//直供入库
        public string DDL_GOODINTYPE_WRITEOFF { get { return "320600"; } }//冲消入库
        public string DDL_GOODINTYPE_PROFIT { get { return "320700"; } }//盘盈入库
        public string DDL_BADINCREATETYPE_CHECK { get { return "11"; } }//检验不合格品
        public string DDL_BADINCREATETYPE_NOMAL { get { return "21"; } }//普通料废
        public string DDL_BADINCREATETYPE_INWARE { get { return "22"; } }//库存料废
        public string DDL_BADINCREATETYPE_OUTRED { get { return "23"; } }//出库冲红

        public DataTable DDL_BASELIST
        {
            get
            {
                SortedList SDList = new SortedList();
                SDList["V_USERID"] = (CURRUSERID == "" ? "-1" : CURRUSERID);
                SDList["V_STATE"] = "1";
                DataTable dtBase = proGetDT(SDList, "PRO_SYS.BASEQUERY");
                return dtBase;
            }
        }
        public DataTable DDL_BASEWARELIST
        {
            get
            {
                SortedList SDList = new SortedList();
                SDList["V_USERID"] = (CURRUSERID == "" ? "-1" : CURRUSERID);
                SDList["V_STATE"] = "1";
                DataTable dtBaseWare = proGetDT(SDList, "PRO_PUBGA.BASEWAREQUERY");
                return dtBaseWare;
            }
        }
        public DataTable DDL_BASEWARELISTBYONE(string strCurrBaseWareID)
        {
            SortedList SDList = new SortedList();
            SDList["V_CURRBASEWAREID"] = strCurrBaseWareID;
            SDList["V_USERID"] = (CURRUSERID == "" ? "-1" : CURRUSERID);
            SDList["V_STATE"] = "1";
            DataTable dtBaseWare = proGetDT(SDList, "PRO_PUBGA.BASEWAREQUERY");
            return dtBaseWare;
        }
        public DataTable DDL_WARELIST
        {
            get
            {
                SortedList SDList = new SortedList();
                SDList["V_USERID"] = CURRUSERID;
                SDList["V_STATE"] = "1";
                DataTable dt = proGetDT(SDList, "PRO_PUBGA.WAREQUERY");
                dt.Columns.Add("WARENAMEC");
                foreach (DataRow dr in dt.Rows)
                {
                    dr["WARENAMEC"] = dr["BASENAME"].ToString() + " " + dr["BASEWARENAME"].ToString() + " " + dr["WARENAME"].ToString();
                }
                return dt;
            }
        }
        public DataTable DDL_WARELIST_GOOD
        {
            get
            {
                SortedList SDList = new SortedList();
                SDList["V_USERID"] = CURRUSERID;
                SDList["V_STATE"] = "999";
                SDList["V_STORETYPE"] = "1";
                DataTable dt = proGetDT(SDList, "PRO_PUBGA.WAREQUERY");
                dt.Columns.Add("WARENAMEC");
                foreach (DataRow dr in dt.Rows)
                {
                    dr["WARENAMEC"] = dr["BASENAME"].ToString() + " " + dr["BASEWARENAME"].ToString() + " " + dr["WARENAME"].ToString();
                }
                return dt;
            }
        }
        public DataTable DDL_WARELIST_TRANSFER
        {
            get
            {
                SortedList SDList = new SortedList();
                SDList["V_USERID"] = CURRUSERID;
                SDList["V_STATE"] = "1";
                SDList["V_READTYPE"] = 4;
                DataTable dt = proGetDT(SDList, "PRO_PUBGA.WAREQUERY");
                dt.Columns.Add("WARENAMEC");
                foreach (DataRow dr in dt.Rows)
                {
                    dr["WARENAMEC"] = dr["BASENAME"].ToString() + " " + dr["BASEWARENAME"].ToString() + " " + dr["WARENAME"].ToString();
                }
                return dt;
            }
        }

        public void DDLBindBaseWare(string strBaseID, bool bQuery, ref DropDownList ddlObj)
        {
            SortedList SDList = new SortedList();
            SDList["V_BASEID"] = strBaseID;
            SDList["V_USERID"] = (CURRUSERID == "" ? "-1" : CURRUSERID);
            SDList["V_STATE"] = 1;
            DataTable dt = proGetDT(SDList, "PRO_PUBGA.BASEWAREQUERY");
            DDLBind(dt, "BASEWARENAME", "KEYID", bQuery, ref ddlObj);
        }
        public void DDLBindBaseFact(string strBaseID, bool bQuery, ref DropDownList ddlObj)
        {
            SortedList SDList = new SortedList();
            SDList["V_BASEID"] = strBaseID;
            SDList["V_STATE"] = 1;
            DataTable dt = proGetDT(SDList, "PRO_PUBGA.BASEFACTQUERY");
            DDLBind(dt, "BASEFACTNAME", "KEYID", bQuery, ref ddlObj);
        }
        public void DDLBindBaseFactCode(string strBaseID, bool bQuery, ref DropDownList ddlObj)
        {
            SortedList SDList = new SortedList();
            SDList["V_BASEID"] = strBaseID;
            SDList["V_STATE"] = 1;
            DataTable dt = proGetDT(SDList, "PRO_PUBGA.BASEFACTQUERY");
            DDLBind(dt, "BASEFACTNAME", "basefactcode", bQuery, ref ddlObj);
        }

        public void DDLBindCurrBaseWare(bool bQuery, ref DropDownList ddlObj)
        {
            DDLBind(DDL_BASEWARELIST, "BASEWARENAMEALL", "KEYID", bQuery, ref ddlObj);
        }

        public void DDLBindUserSupplier(bool bQuery, ref DropDownList ddlObj)
        {
            SortedList SDList = new SortedList();
            SDList["V_USERID"] = CURRUSERID;
            DataTable dt = proGetDT(SDList, "PRO_SYS.USERSUPPLIERQUERY");
            DDLBind(dt, "SUPPLIERCODENAME", "SUPPLIERCODE", bQuery, ref ddlObj);
        }
        #endregion

        #region 下拉字典 
        public string DDLCONFIG(string CONFIGNAME)
        {
            SortedList SDList = new SortedList();
            SDList["V_CONFIGNAME"] = CONFIGNAME;
            string strBack = proGetDTOne(SDList, "PRO_SYS.CONFIGQUERY");
            return strBack;
        }
        public void DDLBindState(bool bQuery, ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("正常", "1"));
            ddlObj.Items.Add(new ListItem("停用", "9"));
            if (bQuery) { ddlObj.Items.Insert(0, new ListItem("==全部==", "")); }
        }
        public void DDLBindYesNo(bool bQuery, ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("是", "1"));
            ddlObj.Items.Add(new ListItem("否", "0"));
            if (bQuery) { ddlObj.Items.Insert(0, new ListItem("==全部==", "")); }
        }
        public void DDLBindGoodInType(bool bQuery, ref DropDownList ddlObj)
        {
            if (bQuery) { ddlObj.Items.Add(new ListItem("==全部==", "")); }
            else { ddlObj.Items.Add(new ListItem("==默认为送检==", "320100")); }

            ddlObj.Items.Add(new ListItem("送检入库", "320100"));
            ddlObj.Items.Add(new ListItem("免检入库", "320200"));
            ddlObj.Items.Add(new ListItem("复检入库", "320300"));
            ddlObj.Items.Add(new ListItem("让步入库", "320400"));
            ddlObj.Items.Add(new ListItem("直供入库", "320500"));
            ddlObj.Items.Add(new ListItem("盘盈入库", "320700"));

        }
        public void DDLBindGoodInState(bool bQuery, ref DropDownList ddlObj)
        {
            if (bQuery) { ddlObj.Items.Add(new ListItem("==全部==", "")); }
            ddlObj.Items.Add(new ListItem("创建", "1"));
            ddlObj.Items.Add(new ListItem("发货", "2"));
            ddlObj.Items.Add(new ListItem("收货", "3"));
            ddlObj.Items.Add(new ListItem("撤销", "9"));
        }
        public void DDLBindGoodOutState(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("创建", "0"));
            ddlObj.Items.Add(new ListItem("部分备料", "11"));
            ddlObj.Items.Add(new ListItem("完成备料", "12"));
            ddlObj.Items.Add(new ListItem("部分出库", "21"));
            ddlObj.Items.Add(new ListItem("完全出库", "22"));
            ddlObj.Items.Add(new ListItem("撤销", "9"));
        }
        public void DDLBindGoodOutStateNew(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("创建", "0"));
            ddlObj.Items.Add(new ListItem("部分出库", "21"));
            ddlObj.Items.Add(new ListItem("完全出库", "22"));
            ddlObj.Items.Add(new ListItem("撤销", "9"));
        }
        public void DDLBindGoodOutItemState(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("申请创建", "1"));
            ddlObj.Items.Add(new ListItem("部分备料", "2"));
            ddlObj.Items.Add(new ListItem("完成备料", "3"));
            ddlObj.Items.Add(new ListItem("出库完成", "4"));
            ddlObj.Items.Add(new ListItem("装车确认", "5"));
            ddlObj.Items.Add(new ListItem("接收确认", "6"));
            ddlObj.Items.Add(new ListItem("明细撤销", "9"));
        }
        public void DDLBindGoodOutItemStateNew(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("申请创建", "1"));
            ddlObj.Items.Add(new ListItem("出库完成", "4"));
            ddlObj.Items.Add(new ListItem("装车确认", "5"));
            ddlObj.Items.Add(new ListItem("接收确认", "6"));
            ddlObj.Items.Add(new ListItem("明细撤销", "9"));
        }
        public void DDLBindTransfer(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("=全部=", ""));
            ddlObj.Items.Add(new ListItem("不中转", "0"));
            ddlObj.Items.Add(new ListItem("待中转", "1"));
            ddlObj.Items.Add(new ListItem("已装车", "2"));
            ddlObj.Items.Add(new ListItem("中转入库", "5"));
            ddlObj.Items.Add(new ListItem("中转出库", "6"));
            ddlObj.Items.Add(new ListItem("撤销", "9"));
        }
        public void DDLBindGoodMoveState(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("创建", "1"));
            ddlObj.Items.Add(new ListItem("配料", "2"));
            ddlObj.Items.Add(new ListItem("完成", "3"));
            ddlObj.Items.Add(new ListItem("撤销", "9"));
        }
        public void DDLBindGoodMoveItemState(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("申请分配", "1"));
            ddlObj.Items.Add(new ListItem("部分分配", "2"));
            ddlObj.Items.Add(new ListItem("完成分配", "3"));
            ddlObj.Items.Add(new ListItem("调度完成", "4"));
            ddlObj.Items.Add(new ListItem("明细撤销", "9"));
        }
        public void DDLBindLoadState(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("创建", "0"));
            ddlObj.Items.Add(new ListItem("确认", "1"));
            ddlObj.Items.Add(new ListItem("未接收", "5"));
            ddlObj.Items.Add(new ListItem("已接收", "6"));
            ddlObj.Items.Add(new ListItem("撤销", "9"));
        }
        public void DDLBindTWDState(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("创建", "0"));
            ddlObj.Items.Add(new ListItem("确认", "1"));
            ddlObj.Items.Add(new ListItem("已出库", "5"));
            ddlObj.Items.Add(new ListItem("已接收", "6"));
            ddlObj.Items.Add(new ListItem("撤销", "9"));
        }
        public void DDLBindISPrint(ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("==全部==", ""));
            ddlObj.Items.Add(new ListItem("未打印", "0"));
            ddlObj.Items.Add(new ListItem("已打印", "1"));
        }
        public void DDLBindBadInCreateType(ref DropDownList ddlObj, bool bQuery)
        {
            //ddlObj.Items.Add(new ListItem("检验不合格品", "11"));
            ddlObj.Items.Add(new ListItem("吉利生产料废", "21"));
            ddlObj.Items.Add(new ListItem("库存料废", "22"));
            //ddlObj.Items.Add(new ListItem("出库冲红", "23"));
            if (bQuery) { ddlObj.Items.Insert(0, new ListItem("==全部==", "")); }
        }
        public void DDLBindOtherBillType(ref DropDownList ddlObj, bool bQuery)
        {
            ddlObj.Items.Add(new ListItem("非看板件", "31"));
            ddlObj.Items.Add(new ListItem("厂家退货", "32"));
            ddlObj.Items.Add(new ListItem("厂家领料", "33"));
            ddlObj.Items.Add(new ListItem("抽检领料", "34"));
            ddlObj.Items.Add(new ListItem("出库冲红", "36"));
            ddlObj.Items.Add(new ListItem("其他出库", "35"));
            if (bQuery) { ddlObj.Items.Insert(0, new ListItem("==全部==", "")); }
        }
        public void DDLBindISEnter(bool bQuery, ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("已入驻", "1"));
            ddlObj.Items.Add(new ListItem("未入驻", "0"));
            if (bQuery) { ddlObj.Items.Insert(0, new ListItem("==全部==", "")); }
        }

        #region 对拉下拉框
        protected void DDLBindDLPackState(DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("已装", "0"));
            //ddlObj.Items.Add(new ListItem("起始库出库", "1"));
            //ddlObj.Items.Add(new ListItem("中转入库", "11"));
            //ddlObj.Items.Add(new ListItem("中转出库", "15"));
            //ddlObj.Items.Add(new ListItem("目标库入库", "21"));
            //ddlObj.Items.Add(new ListItem("目标库已拆包", "22"));
            //ddlObj.Items.Add(new ListItem("目标库出库", "25"));
            DDLBindLeaveType(false, ref ddlObj);
            ddlObj.Items.Add(new ListItem("撤销", "9"));
            ddlObj.Items.Insert(0, new ListItem("--全部--", ""));
        }

        protected void DDLBindLeaveType(bool bQuery, ref DropDownList ddlObj)
        {
            ddlObj.Items.Add(new ListItem("起始库出库", "1"));
            ddlObj.Items.Add(new ListItem("中转入库", "11"));
            ddlObj.Items.Add(new ListItem("中转出库", "15"));
            ddlObj.Items.Add(new ListItem("目标库入库", "21"));
            ddlObj.Items.Add(new ListItem("目标库已拆包", "22"));
            ddlObj.Items.Add(new ListItem("目标库出库", "25"));
            if (bQuery) { ddlObj.Items.Insert(0, new ListItem("--全部--", "")); }
        }

        #endregion

        public DataTable DDLBind(string strType)
        {
            SortedList SDList = new SortedList();
            SDList["V_TYPENAME"] = strType;
            SDList["V_DDLSTATE"] = 1;
            DataTable dtDDL = proGetDT(SDList, "PRO_SYS.DDLQUERY");
            return dtDDL;
        }
        /// <summary>
        /// DDL下拉绑定
        /// </summary>
        /// <param name="strType">类型</param>
        /// <param name="bQuery">是否全部</param>
        /// <param name="ddlObj">DDL对象</param>
        public void DDLBind(string strType, bool bQuery, ref DropDownList ddlObj)
        {
            DataTable dtDDL = DDLBind(strType);
            DDLBind(dtDDL, "DDLNAME", "DDLID", bQuery, ref ddlObj);
        }
        /// <summary>
        /// DDL下拉绑定
        /// </summary>
        /// <param name="dtBind">数据表</param>
        /// <param name="strTextID">Text</param>
        /// <param name="strValueID">Value</param>
        /// <param name="bQuery">是否全部</param>
        /// <param name="ddlObj">DDL对象</param>
        public void DDLBind(DataTable dtBind, string strTextID, string strValueID, bool bQuery, ref DropDownList ddlObj)
        {
            if (ddlObj == null) { return; }
            if (dtBind != null)
            {
                ddlObj.DataSource = dtBind;
                ddlObj.DataValueField = strValueID;
                ddlObj.DataTextField = strTextID;
                ddlObj.DataBind();
            }
            if (bQuery) { ddlObj.Items.Insert(0, new ListItem("==全部==", "")); }
        }
        public void DDLBindValue(string strValue, ref DropDownList ddlObj)
        {
            if (ddlObj.Items.FindByValue(strValue) != null)
            {
                ddlObj.SelectedValue = strValue;
            }
        }
        #endregion

        #region 类型名称
        #region 看板类型名称
        public string GetLINKBILLTYPE2(string LINKBILLTYPE2)
        {
            string reStr = "二级";
            if (LINKBILLTYPE2 == "22")
                reStr = "<font color='blue'>直供</font>";
            else if (LINKBILLTYPE2 == "21")
                reStr = "<font color='#BBAA21'>配套</font>";
            else if (LINKBILLTYPE2 == "23")
                reStr = "<font color='#009933'>P链</font>";
            return reStr;
        }
        #endregion
        #endregion

        #region 常用返回
        public string strDateLen(string strIn, int len) { return (len == 19 ? strDateTime(strIn) : strDate(strIn)); }
        public string strDate(string strIn)
        {
            return (strIn.ToString() == "" ? "" : Convert.ToDateTime(strIn).ToString("yyyy-MM-dd"));
        }
        public string strDateTime(string strIn)
        {
            return (strIn.ToString() == "" ? "" : Convert.ToDateTime(strIn).ToString("yyyy-MM-dd HH:mm:ss"));
        }
        public string strDate()
        {
            return System.DateTime.Now.ToString("yyyy-MM-dd");
        }
        public string strDateTime()
        {
            return System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        public string strDateTimeHM()
        {
            return System.DateTime.Now.ToString("yyyy-MM-dd 00:00");
        }
        public string strDateTimeJT()
        {
            return System.DateTime.Now.ToString("yyyy-MM-dd HH:mm");
        }

        public decimal decGetByStr(string strIn) { try { return Convert.ToDecimal(strIn); } catch { return 0; } }

        public string getNEWKEYID { get { return Guid.NewGuid().ToString().Replace("-", ""); } }
        public string getKEYIDBYByte(object TT) { try { return BitConverter.ToString((byte[])TT).Replace("-", ""); } catch { return ""; } }

        public bool HaveHtml(string str)
        {
            string html = "'|.|<|>|%|^|*|,";
            string[] htmlarr = html.Split('|');
            string temp = str;
            for (int i = 0; i < htmlarr.Length; i++)
            {
                if (temp.IndexOf(htmlarr[i]) >= 0)
                    return false;
            }
            return true;
        }
        #endregion

        //==========================================

        #region 列表排序 
        protected string GetSortDirectiont(string strSortExpressionView, string strSortDirectionView)
        {
            string[] SortColumnAll = strSortExpressionView.Split('$');
            string[] DirectionAll = strSortDirectionView.Split('$');
            string strBack = "";
            for (int i = 0; i < SortColumnAll.Length; i++)
            {
                if (SortColumnAll[i] != "")
                {
                    strBack += (strBack == "" ? "" : ",") + SortColumnAll[i] + " " + DirectionAll[i];
                }
            }
            return strBack;
        }
        protected void AddSortColumn(ref object sender, string SortColumn, ref string SortExpressionView, ref string SortDirectionView)
        {

            #region 原排序 有误
            //string SortColumnAll = SortExpressionView;
            //string[] SortColumnOneS = SortColumnAll.Split('$');
            //int iColumnCount = -1;
            //for (int i = 0; i < SortColumnOneS.Length; i++)
            //{
            //    if (SortColumnOneS[i] == SortColumn)
            //    {
            //        iColumnCount = i; 
            //        break;
            //    }
            //}
            //string DirectionAll = SortDirectionView;
            //if (iColumnCount >= 0)
            //{
            //    string[] DirectionOneS = SortDirectionView.Split('$');
            //    if (DirectionOneS[iColumnCount] == "ASC")
            //    {
            //        DirectionOneS[iColumnCount] = "DESC";
            //    }
            //    else
            //    {
            //        DirectionOneS[iColumnCount] = "";
            //        SortColumnOneS[iColumnCount] = "";
            //    }
            //    strFIELDNAME = SortColumnOneS[iColumnCount]; strFILEDDESC = DirectionOneS[iColumnCount];

            //    SortColumnAll = "";
            //    DirectionAll = "";
            //    for (int i = 0; i < DirectionOneS.Length; i++)
            //    {
            //        if (DirectionOneS[i] != "")
            //        {
            //            SortColumnAll += ((SortColumnAll == "" ? "" : "$") + SortColumnOneS[i]);
            //            DirectionAll += ((DirectionAll == "" ? "" : "$") + DirectionOneS[i]);
            //        }
            //    }
            //    SortExpressionView = SortColumnAll;
            //    SortDirectionView = DirectionAll;
            //}
            //else if (SortColumn != "")
            //{
            //    SortExpressionView += ((SortExpressionView == "" ? "" : "$") + SortColumn);
            //    SortDirectionView += ((SortDirectionView == "" ? "" : "$") + "ASC");
            //    strFIELDNAME = SortColumn; strFILEDDESC = "ASC";
            //}
            #endregion

            if (SortExpressionView != "" && SortExpressionView == SortColumn && SortDirectionView == "ASC")
            {
                SortDirectionView = "DESC";
            }
            else
            {
                SortDirectionView = "ASC";
            }
            SortExpressionView = SortColumn;
            string strFIELDNAME = SortExpressionView, strFILEDDESC = SortDirectionView;

            for (int i = 0; i < ((GridView)sender).Columns.Count; i++)
            {
                string strHeadText = ((GridView)sender).Columns[i].HeaderText;
                strHeadText = strHeadText.Replace("↓", "").Replace("↑", "");
                if (((GridView)sender).Columns[i].SortExpression == strFIELDNAME)
                {
                    if (strFILEDDESC == "ASC") { strHeadText += "↑"; }
                    if (strFILEDDESC == "DESC") { strHeadText += "↓"; }
                }
                ((GridView)sender).Columns[i].HeaderText = strHeadText;
            }

        }
        #endregion

        //==========================================

        #region excel导入导出

        #region 导入excel 
        public DataTable ExcelToDataSet(FileUpload FileUpload1)
        {
            try
            {
                string strFileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
                string[] strTT = strFileName.Split('.');
                if (strTT.Length < 2) { return null; }
                if (strFileName == "") { return null; }
                string FileFullPath = MapPath("../PUB/FILE/TEMP/") + DateTime.Now.ToString("yyyyMMddHHmmss") + strFileName;
                FileUpload1.PostedFile.SaveAs(FileFullPath);

                return (strTT[1].ToUpper() == "CSV" || strTT[1].ToUpper() == "TXT" ? CsvToDataSet(FileFullPath) : ExcelToDataSet(FileFullPath));
            }
            catch (Exception ex)
            {
                proSaveErro("导入数据处理：" + "\n" + ex.ToString());
                return null;
            }
        }
        public DataTable ExcelToDataSet(string path)
        {
            if (path == string.Empty) { return null; }
            OleDbConnection conn = null;
            try
            {
                string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + path + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";  // 这里excel03 如要该成07版再问我或者百度
                if (path.ToLower().IndexOf(".xlsx") > 0)
                {
                    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';Extended Properties='Excel 12.0;HDR=YES; IMEX=1'";
                }
                conn = new OleDbConnection(strConn);
                conn.Open();
                DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                string tableName = dt.Rows[0][2].ToString().Trim();
                string strExcel = "select * from [" + tableName + "]";
                OleDbDataAdapter oleda = new OleDbDataAdapter(strExcel, strConn);
                DataSet ds = new DataSet();
                oleda.Fill(ds);
                oleda.Dispose();
                return ds.Tables[0];
            }
            catch (Exception ex)
            {
                proSaveErro("导入数据处理：" + path + "\n" + ex.ToString());
                return null;
            }
            finally
            {
                conn.Close();
            }
        }
        public DataTable CsvToDataSet(string files)
        {
            StreamReader fileReader = new StreamReader(files, Encoding.Default);
            try
            {
                DataTable dt = new DataTable(); dt.Columns.Add("tt");
                while (fileReader.EndOfStream == false)
                {
                    string line = fileReader.ReadLine();
                    DataRow dr = dt.NewRow();
                    dr["tt"] = line;
                    dt.Rows.Add(dr);
                }
                return dt;
            }
            catch (Exception ex)
            {
                proSaveErro("导入数据处理：" + files + "\n" + ex.ToString());
                return null;
            }
            finally
            {
                fileReader.Close();
                fileReader.Dispose();
            }
        }
        #endregion

        #region 导出EXCEL
        //导出EXCEL
        public void ExceptExcel(GridView gv)
        {
            ExceptExcel(gv, "FileName");
        }
        public void ExceptExcel(GridView gv, string strFileName)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + strFileName + ".xls");
            // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码！！！
            Response.ContentEncoding = System.Text.Encoding.UTF7;
            Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            gv.RenderControl(oHtmlTextWriter);
            Response.Output.Write(oStringWriter.ToString());
            Response.Flush();
            Response.End();
        }

        #region 导出Excel2
        /// <summary>
        /// 按列表显示的列导出Excel
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="gv">显示列表</param>
        /// <param name="strFileName">导出的文件名</param>
        protected void ExceptExcelAll(DataTable dt, GridView gv, string strFileName)
        {
            GridView gvOut = new GridView();
            gvOut.AutoGenerateColumns = false;
            gvOut.AllowPaging = false;
            gvOut.CssClass = gv.CssClass;
            gvOut.HeaderStyle.CssClass = gvOut.HeaderStyle.CssClass;
            gvOut.RowStyle.CssClass = gvOut.RowStyle.CssClass;
            gvOut.AlternatingRowStyle.CssClass = gvOut.AlternatingRowStyle.CssClass;
            for (int i = 0; i < gv.Columns.Count; i++)
            {
                if (gv.Columns[i].GetType().Name == "BoundField" && gv.Columns[i].HeaderText != "")  //肯定是可以显示的数据帮定字段 BoundField HeaderText="" 可以规避隐藏列
                {
                    BoundField bf = new BoundField();
                    bf.HeaderText = gv.Columns[i].HeaderText;
                    bf.DataField = ((BoundField)gv.Columns[i]).DataField;
                    gvOut.Columns.Add(bf);
                }
            }
            gvOut.DataSource = dt;
            gvOut.DataBind();
            foreach (GridViewRow dr in gvOut.Rows)
            {
                foreach (TableCell tc in dr.Cells)
                {
                    tc.Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                }
            }
            ExceptExcel2(gvOut, strFileName);
        }
        /// <summary>
        /// 按标题集合导出Excel
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="strHeaderTexts">标题名称集合</param>
        /// <param name="strDataFields">标题名称集合</param>
        /// <param name="strFileName">导出的文件名</param>
        protected void ExceptExcelAll(DataTable dt, string strHeaderTexts, string strDataFields, string strFileName)
        {
            GridView gvOut = new GridView();
            gvOut.AutoGenerateColumns = false;
            gvOut.AllowPaging = false;
            gvOut.CssClass = "";
            gvOut.HeaderStyle.CssClass = gvOut.HeaderStyle.CssClass;
            gvOut.RowStyle.CssClass = gvOut.RowStyle.CssClass;
            gvOut.AlternatingRowStyle.CssClass = gvOut.AlternatingRowStyle.CssClass;

            string[] headerTexts = strHeaderTexts.Replace(" ", "").Replace("，", ",").Split(',');
            string[] dataFields = strDataFields.Replace(" ", "").Replace("，", ",").Split(',');
            for (int i = 0; i < headerTexts.Length; i++)
            {
                BoundField bf = new BoundField();
                bf.HeaderText = headerTexts[i];
                bf.DataField = dataFields[i];
                gvOut.Columns.Add(bf);
            }

            gvOut.DataSource = dt;
            gvOut.DataBind();
            foreach (GridViewRow dr in gvOut.Rows)
            {
                foreach (TableCell tc in dr.Cells)
                {
                    tc.Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                }
            }
            ExceptExcel2(gvOut, strFileName);
        }

        public void ExceptExcel2(GridView gvOut, string strFileName)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";
            if (string.IsNullOrEmpty(strFileName))
            {
                strFileName = "XLS" + DateTime.Now.ToString("yyyyMMddHHmmss");
            }
            string expFileName = "attachment;filename=" + strFileName + ".xls";
            //if (rExecTypeDoc.Checked)
            //{
            //    expFileName = "attachment;filename=" + "DOC" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";
            //}
            Response.AppendHeader("Content-Disposition", expFileName);
            Response.ContentType = "application/ms-excel";
            this.EnableViewState = false;
            System.IO.StringWriter swOut = new System.IO.StringWriter();
            HtmlTextWriter hTw = new HtmlTextWriter(swOut);
            gvOut.RenderControl(hTw);
            Response.Write(swOut.ToString());
            Response.End();
        }
        #endregion


        #endregion

        #endregion

        //========================================== 

        #region 共用继承 

        #region GetLocalIP
        public static string GetLocalIP()
        {
            try
            {
                string HostName = Dns.GetHostName(); //得到主机名
                IPHostEntry IpEntry = Dns.GetHostEntry(HostName);
                for (int i = 0; i < IpEntry.AddressList.Length; i++)
                {
                    if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                    {
                        return IpEntry.AddressList[i].ToString();
                    }
                }
                return "";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        #endregion

        #region currPageCount
        public string strReqPageCount()
        {
            if (Request["MENUID"] != null && Request["MENUID"].ToString() != "" && Session["PAGEROW_" + Request["MENUID"].ToString()] != null)
            {
                return Session["PAGEROW_" + Request["MENUID"].ToString()].ToString();
            }

            if (Request["PAGECOUNT"] != null && Request["PAGECOUNT"].ToString() != "")
            {
                return Request["PAGECOUNT"].ToString();
            }
            else
            {
                return "25";
            }
        }
        #endregion

        #region userGrid
        protected void dgList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }
        protected void dgList_Sorting(object sender, GridViewSortEventArgs e)
        {
            string strSortExpression = (ViewState["SortExpression"] == null ? "" : ViewState["SortExpression"].ToString());
            string strSortDirection = (ViewState["SortDirection"] == null ? "" : ViewState["SortDirection"].ToString());
            AddSortColumn(ref sender, e.SortExpression, ref strSortExpression, ref strSortDirection);
            ViewState.Add("SortExpression", strSortExpression);
            ViewState.Add("SortDirection", strSortDirection);
            pageBind();
        }
        #endregion

        #region userListDo
        protected void btn_Click(object sender, EventArgs e)
        {
            dgListBaseDo(((Button)(sender)).CommandName, ((Button)(sender)).CommandArgument);
        }
        protected void lbtn_Click(object sender, EventArgs e)
        {
            dgListBaseDo(((LinkButton)(sender)).CommandName, ((LinkButton)(sender)).CommandArgument);
        }
        protected void ibtn_Click(object sender, EventArgs e)
        {
            dgListBaseDo(((ImageButton)(sender)).CommandName, ((ImageButton)(sender)).CommandArgument);
        }
        protected void dgList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            dgListBaseDo(e.CommandName, e.CommandArgument.ToString());
        }
        protected void dgListDetail_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            dgListBaseDo(e.CommandName, e.CommandArgument.ToString());
        }
        protected virtual void dgListBaseDo(string strCommandName, string strCommandArgument)
        {
            #region 查询
            if (strCommandName == "查询")
            {
                pageBindReset();
                pageBind();
                return;
            }
            #endregion

            #region 关闭
            if (strCommandName == "关闭")
            {
                pageBind();
                return;
            }
            #endregion

            dgListDo(strCommandName, strCommandArgument);
        }
        #endregion

        protected virtual void pageInit() { }
        protected virtual void pageBindReset() { }
        protected virtual void pageBind() { }
        protected virtual void dgListDo(string strCommandName, string strCommandArgument) { }

        #endregion

        //==========================================
    }
}